package com.javachamp.collections;

import java.util.SortedMap;
import java.util.TreeMap;

public class TreeMapDemo {

	static TreeMap<Integer, String> map = new TreeMap<Integer, String>();
	
	static {
		map.put(1, "a");
		map.put(3, "c");
		map.put(2, "b");
		map.put(7, "g");
		map.put(4, "d");
		map.put(9, "j");
		map.put(8, "h");
		map.put(5, "e");
		map.put(6, "f");
	}

	public static void main(String[] args) {
		System.out.println(map);
		
		System.out.println(map.tailMap(5));
		System.out.println(map.headMap(5));
		System.out.println(map.subMap(4, 6));
		
		System.out.println(map.ceilingEntry(1));
		System.out.println(map.ceilingEntry(2));
		
		System.out.println(map.lowerEntry(1));
		System.out.println(map.lowerEntry(2));
		
		System.out.println(map.higherEntry(8));
		System.out.println(map.higherEntry(9));
		
		System.out.println(map.pollFirstEntry());
		System.out.println(map.pollLastEntry());
		
		System.out.println(map);
	}
	
}
